﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace RoadTeam.FineFile
{
    public partial class Re_Old_Release : Form
    {
        public Re_Old_Release()
        {
            InitializeComponent();
            LoadPath();
        }

        public void LoadPath()
        {
            Dictionary<string, string> dict = ReadWrite.ReadFile();
            if (dict.Keys.Contains(textBox1.Name))
                textBox1.Text = dict[textBox1.Name];
            if (dict.Keys.Contains(textBox2.Name))
                textBox2.Text = dict[textBox2.Name];
            if (dict.Keys.Contains(textBox3.Name))
                textBox3.Text = dict[textBox3.Name];
        }
        private void Form4_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fd1 = new FolderBrowserDialog();
            if (fd1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = fd1.SelectedPath;
                ReadWrite.WriteFile("textBox1|" + textBox1.Text);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fd1 = new FolderBrowserDialog();
            if (fd1.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = fd1.SelectedPath;
                ReadWrite.WriteFile("textBox2|" + textBox2.Text);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            op.Filter = "*.txt|";
            if (op.ShowDialog() == DialogResult.OK)
            {
                textBox3.Text = op.FileName;
                ReadWrite.WriteFile("textBox3|" + textBox3.Text);
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            ReadWrite.WriteFile("textBox3|" + textBox3.Text);
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            ReadWrite.WriteFile("textBox2|" + textBox2.Text);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            ReadWrite.WriteFile("textBox1|" + textBox1.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("发布网站路径不能为空"); return;
            }

            if (String.IsNullOrEmpty(textBox2.Text))
            {
                MessageBox.Show("文件取出路径不能为空"); return;
            }

            if (String.IsNullOrEmpty(textBox3.Text))
            {
                MessageBox.Show("TXT文档不能为空"); return;
            }

            //打包文件算法
            try
            {
                FileOpera fio = new FileOpera();
                List<String> liPath = ReadWrite.GetPathList(textBox3.Text);
                IGetPath FullPath = new GetOldFullPath();
                List<String> PathFileName = FullPath.GetFileFullPath(liPath, textBox1.Text);

                FileOpera opere;
                Thread[] threas = new Thread[PathFileName.Count];

                progressBar1.Value = 0;
                progressBar1.Step = 1;
                progressBar1.Maximum = PathFileName.Count;

                for (int i = 0; i < threas.Length; i++)
                {
                    opere = new FileOpera();
                    opere.SourceDir = textBox1.Text;
                    opere.OutDir = textBox2.Text;
                    opere.FileDirAndName = PathFileName[i];
                    ThreadStart ths = new ThreadStart(opere.CopyFile);
                    threas[i] = new Thread(ths);
                    threas[i].Start();
                    progressBar1 .Value+= progressBar1.Step;
                }

                MessageBox.Show("获取文件成功");
            }
            catch (Exception EX)
            {
                MessageBox.Show("报了[" + EX.Message + "]错误;目测缺水,找盆水泼进去机箱就可以了");
            }

        }





    }
}
